<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */
    
    /*********************************************************
    *            --== InArch ==--
    * @author Kulikov Alexey <a.kulikov@gmail.com>
    * @version n/a
    * @since 16.08.2005
    * @copyright essentialmind.com 2005
    *
    *********************************************************/
    
    /***
    * Abstract Class installNode
    ****
    * This is the module installer/deinstaller, shall
    * automate integration of new modules into client
    * solutions
    ****
    * @package usefulStuff
    * @author A Kulikov <a.kulikov@gmail.com>
    * @version n/a
    * @since 16.08.2005
    * @copyright essentialmind.com 2005
    ***/
    class fileSystem{
        
        
        public function __construct(){
            //nathin!   
        }
        
        
        /**
         * Will copy a folder and all its contents to a new destination
         *
         * @param string $source
         * @param string $dest
         * @return bool
         */
        public function copyDirs($source, $dest, $chmod=0777){
            // Simple copy for a file
            if(is_file($source)) {
                return copy($source, $dest);
            }
         
            // Make destination directory
            if (!is_dir($dest)) {
                mkdir($dest, $chmod);
            }
         
            // Loop through the folder
            $dir = dir($source);
            while (false !== $entry = $dir->read()) {
                // Skip pointers
                if ($entry == '.' || $entry == '..') {
                    continue;
                }
         
                // Deep copy directories
                if ($dest !== $source.DIRECTORY_SEPARATOR.$entry) {
                    $this->copyDirs($source.DIRECTORY_SEPARATOR.$entry, $dest.DIRECTORY_SEPARATOR.$entry);
                }
            }
         
            // Clean up
            $dir->close();
            return true;
        }
        
        
        
        /**
         * Prepares the upload path, tring to create a directory tree on the system
         * where it is needed
         *
         * @param string $uploadPath
         * @param octal $chmod
         * @access private
         */
        public function createPath($uploadPath,$chmod=0777){
            //check if directory exists, if not, attempt to create it
			if(!is_dir($uploadPath) and !is_file($uploadPath)){

			    //explode the whole path into compontents
			    $tempPathArray   = explode(DIRECTORY_SEPARATOR,$uploadPath);
			    $tempPath        = null;
			    
			    //cycle through the array attempting to create anything that does not exist
			    foreach($tempPathArray as $directory){
                    $tempPath .= $directory . DIRECTORY_SEPARATOR;
                    
                    if(!is_dir($tempPath)){
                        @mkdir($tempPath, $chmod);
				        @chmod($tempPath, $chmod);
                    }
			    }	    
			}
        }
    }
?>